﻿using System;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Media;

namespace Bookvar.UI.Converters
{
    public class UriToImageSourceConverter : IValueConverter
    {
        #region IValueConverter Members

        public object Convert( object value, Type targetType, object parameter, CultureInfo culture )
        {
            string size = "M";
            var sizeString = parameter as string;
            if ( sizeString != null )
            {
                size = sizeString;
            }
            return new ImageSourceConverter().ConvertFrom(
                string.Format( CultureInfo.InvariantCulture, "http://images.websnapr.com/?url={0}&size={1}", value, size ) );
        }

        public object ConvertBack( object value, Type targetType, object parameter, CultureInfo culture )
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}